/**
 * @author 徐楠
 * @date 2022/4/23 23:21
 * @version 1.0
 */

package com.xunan.likou;

public class ReverseStringThree {
    public static void main(String[] args) {
        //String s = "God Ding";
        String s = "Let's take LeetCode contest";
        String result = reverseWords(s);
        System.out.println(result);
    }

    public static String reverseWords(String s) {
        String[] s1 = s.split(" ");
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < s1.length; i++) {
            String s2 = s1[i];
            char[] chars = s2.toCharArray();
            for (int j = 0; j < chars.length / 2; j++) {
                char temp = chars[j];
                chars[j] = chars[chars.length - 1 - j];
                chars[chars.length - 1 - j] = temp;
            }
            stringBuffer.append(chars);
            if (s1.length - 1 != i) {
                stringBuffer.append(" ");
            }
        }
        return stringBuffer.toString();
    }
}
